import axios from 'axios';
import { message } from 'antd';
const isDev = process.env.NODE_ENV === 'development';
const service = axios.create({
  baseURL: isDev ? 'http://rap2api.taobao.org/app/mock/243997/' : ''
});
const serviece1 = axios.create({
  baseURL: isDev ? 'http://rap2api.taobao.org/app/mock/243997/' : ''
});
//设置统一的请求头token
service.interceptors.request.use(config => {
  //请求拦截器
  config.data = Object.assign({}, config.data, {
    authToken: 'ititokenplaceholder'
  });
  return config;
});
service.interceptors.response.use(res => {
  //对数据进行处理
  if (res.data.code === 200) return res.data;
  else {
    //全局处理错误
    message.error(res.data.errMsg);
  }
});
export const getArticals = (offset = 0, limited = 10) => {
  return service.post('api/v1/articalList', {
    offset, //页数
    limited //每页几条数据
  });
};
export const deleteArticle = id => {
  return service.post(`api/v1/articleDelete/${id}`);
};
export const getArticleById = id => {
  return service.post(`api/v1/article/${id}`);
};
export const saveArticle = (id, data) => {
  return service.post(`api/v1/articleEdit/${id}`, data);
};
export const getAllNotifications = () => {
  return service.post('api/v1/notifications');
};
export const getUserInfo = userInfo => {
  return serviece1.post('/api/v1/login', userInfo);
};
